﻿using System;
using System.Xml.Xsl;

namespace Xmlt.ViewEngine
{
    internal class XsltTransformCache
    {
        private XsltTransformCache() { }

        public static XslCompiledTransform Get(string key)
        {
            return System.Web.HttpRuntime.Cache[key] as XslCompiledTransform;
        }

        public static void Set(string key, XslCompiledTransform transform)
        {
            System.Web.HttpRuntime.Cache.Add(key, transform, null, DateTime.MaxValue, TimeSpan.MaxValue,
                System.Web.Caching.CacheItemPriority.Normal, null);
        }

        public static void Set(string key, XslCompiledTransform transform, System.Web.Caching.CacheDependency cacheDependency)
        {
            System.Web.HttpRuntime.Cache.Add(key, transform, cacheDependency, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration,
                System.Web.Caching.CacheItemPriority.Normal, new System.Web.Caching.CacheItemRemovedCallback((s, o, r) =>
                {
                    System.Diagnostics.Debugger.Log(0, "Cache item removed", string.Format("Cache item '{0}' removed.\n", s));
                }));
        }
    }
}
